package com.jxt.myapp.dao;

import java.util.ArrayList;
import java.util.List;

import com.jxt.myapp.domain.DbUser;

public class UserDao {

	public DbUser searchDatabase(String username) {
		List<DbUser> users = internalDatabase();

		for (DbUser dbUser : users) {
			if (dbUser.getUsername().equals(username) == true) {
				return dbUser;
			}
		}

		throw new RuntimeException("User does not exist!");
	}

	private List<DbUser> internalDatabase() {

		List<DbUser> users = new ArrayList<DbUser>();
		DbUser user = null;
		user = new DbUser();
		user.setUsername("admin");
		// Actual password: admin
		user.setPassword("21232f297a57a5a743894a0e4a801fc3");
		// Admin user
		user.setAccess(1);

		// Add to array list
		users.add(user);

		// Create a new dummy user
		user = new DbUser();
		user.setUsername("user");
		// Actual password: user
		user.setPassword("ee11cbb19052e40b07aac0ca060c23ee");
		// Regular user
		user.setAccess(2);

		// Add to array list
		users.add(user);

		return users;

	}

}
